package com.google.code.p.ivans;

import java.io.IOException;
import java.sql.SQLException;

import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cafe.ejb.WaitersOrdersService;



/**
 * Servlet implementation class RemoveOrderLink
 */
public class RemoveOrderLink extends HttpServlet {
	
	private static final long serialVersionUID = 1L;	
	
	@EJB
	WaitersOrdersService waitersOrdersSI;
   
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		long waiterId = Long.valueOf(request.getParameter("waiterId"));
		long orderId = Long.valueOf(request.getParameter("orderId"));
		
		try {
			waitersOrdersSI.removeLink(waiterId, orderId);
			request.setAttribute("result", "Связь успешно удалена");
			
		} catch (SQLException e) {
			request.setAttribute("result", "Не удалось удалить связь. Причина:" + e.getMessage());
		}
		
		RequestDispatcher requestDispatcher = request.getRequestDispatcher("resultOfRemovingLink.jsp");			
		requestDispatcher.forward(request, response);
	}
}
